/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package xfer;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
 *
 * @author Jude Lucien
 * JLucien@gmail.com
 */
public class CreateWindow extends JPanel implements ActionListener{
    
    static String scpString = "SCP (Secure Copy)";
    static String ftpString = "File Transfer Protocol";
    static String httpString = "HTTP";
    static String sslString = "HTTPS";
    static String rsyncString = "Rsync over SSH";

    JLabel picture;

    public CreateWindow() {
        super(new BorderLayout());

        //Create the radio buttons.
        JRadioButton scpButton = new JRadioButton(scpString);
        scpButton.setMnemonic(KeyEvent.VK_S);
        scpButton.setActionCommand(scpString);
        scpButton.setSelected(true);

        JRadioButton ftpButton = new JRadioButton(ftpString);
        ftpButton.setMnemonic(KeyEvent.VK_F);
        ftpButton.setActionCommand(ftpString);

        JRadioButton httpButton = new JRadioButton(httpString);
        httpButton.setMnemonic(KeyEvent.VK_H);
        httpButton.setActionCommand(httpString);

        JRadioButton sslButton = new JRadioButton(sslString);
        sslButton.setMnemonic(KeyEvent.VK_L);
        sslButton.setActionCommand(sslString);

        JRadioButton rsyncButton = new JRadioButton(rsyncString);
        rsyncButton.setMnemonic(KeyEvent.VK_R);
        rsyncButton.setActionCommand(rsyncString);

        //Group the radio buttons.
        ButtonGroup group = new ButtonGroup();
        group.add(scpButton);
        group.add(ftpButton);
        group.add(httpButton);
        group.add(sslButton);
        group.add(rsyncButton);

        //Register a listener for the radio buttons.
        scpButton.addActionListener(this);
        ftpButton.addActionListener(this);
        httpButton.addActionListener(this);
        sslButton.addActionListener(this);
        rsyncButton.addActionListener(this);

        //Set up the picture label.
        picture = new JLabel(createImageIcon("icon.jpg"));

        //The preferred size is hard-coded to be the width of the
        //widest image and the height of the tallest image.
        //A real program would compute this.
        picture.setPreferredSize(new Dimension(250, 250));


        //Put the radio buttons in a column in a panel.
        JPanel radioPanel = new JPanel(new GridLayout(0, 1));
        radioPanel.add(scpButton);
        radioPanel.add(ftpButton);
        radioPanel.add(httpButton);
        radioPanel.add(sslButton);
        radioPanel.add(rsyncButton);

        add(radioPanel, BorderLayout.LINE_START);
        add(picture, BorderLayout.CENTER);
        setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
    }

    /** Listens to the radio buttons. */
    public void actionPerformed(ActionEvent e) {
        picture.setIcon(createImageIcon("images/"
                                        + e.getActionCommand()
                                        + ".gif"));
    }

    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = CreateWindow.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }

    
}

